Path: blob/master/Part 9 - Dimension Reduction/Linear Discriminant Analysis/[Python] Linear Discriminant Analysis.ipynb
1339 views
Kernel: Python 3
Linear Discriminant Analysis
Data preprocessing
In [1]:
In [2]:
Out[2]:
In [3]:
Out[3]:
In [4]:
In [5]:
Out[5]:
array([ 14.23, 1.71, 2.43, 15.6 , 127. , 2.8 ,
3.06, 0.28, 2.29, 5.64, 1.04, 3.92, 1065. ])
In [6]:
In [7]:
Applying Linear Discriminant Analysis
In [8]:
In [9]:
Out[9]:
array([-3.17092336, 2.12434125])
In [10]:
Out[10]:
array([ 5.43777422, 2.52448581])
Fitting Logistic Regression to the Training Set
In [11]:
Out[11]:
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,
penalty='l2', random_state=42, solver='liblinear', tol=0.0001,
verbose=0, warm_start=False)
Predicting Test set result
In [12]:
In [13]:
Out[13]:
array([1, 1, 3, 1, 2, 1, 2, 3, 2, 3])
In [14]:
Out[14]:
array([1, 1, 3, 1, 2, 1, 2, 3, 2, 3])
Making the Confusion Matrix
In [15]:
Out[15]:
array([[14, 0, 0],
[ 0, 14, 0],
[ 0, 0, 8]])
Here we have almost no incorrect prediction at all.
Accuracy
In [16]:
Out[16]:
1.0
Visualizing the training set results
In [17]:
Out[17]:
<matplotlib.legend.Legend at 0x7f5a13940da0>
Visualizing the test set results
In [18]:
Out[18]:
<matplotlib.legend.Legend at 0x7f5a09f124e0>